<?php

namespace App\Jobs\QiPao;

use App\Jobs\Job;
use App\Services\Tools\IdempotentConsume;
use Illuminate\Support\Facades\Log;

class ConnectBoxJob extends Job
{
    protected $data;//
    const jobName = 'ConnectBoxJob';
    
    /**
     * Create a new job instance.
     * @return void
     */
    public function __construct($data)
    {
        $this->data = $data;
    }
    
    /**
     * Execute the job.
     * @return void
     */
    public function handle()
    {
        if(env('APP_ENV') != 'production'){
            Log::error('ConnectBoxJob:' . json_encode(['time' => getMillisecond(), 'data' => $this->data]));
        }
        $data = $this->data;
        $idempotentConsumeServer = new IdempotentConsume();
        try{
            if($idempotentConsumeServer->checkIdempotentRedisKey(self::jobName, $data['uk'])){
                $res = app('repo_new_connect')->openConnectGiftBoxOperate($data);
                var_dump($res);
                if(!$res){
                    $idempotentConsumeServer->deleteIdempotentRedisKey(self::jobName, $data['uk']);
                }
            }
        }catch (\Exception $e){
            $idempotentConsumeServer->deleteIdempotentRedisKey(self::jobName, $data['uk']);
        }
       
    }

}
